#include<iostream>
#include<queue>
using namespace std;
class memnode
{
	public:
		memnode* next;
		memnode* pre;
		memnode* nextFree;
		int size;
		bool free;
		int startAdress;
		memnode(int initsize)
		{
			size=initsize;
			next=NULL;
			pre=NULL;
			nextFree=NULL;
			free=true;
			startAdress=0;
		}

		void release();

		void merge()
		{
			if(free)
			{
				if(pre != NULL && pre->free)
				{
					memnode * temp=pre;
					temp->size += size;
					temp->next= next;
					if(next!=NULL)
						next->pre=temp;
					temp->nextFree = nextFree;
					
					if(next !=NULL && next->free)
					{
						next->merge();
					}

					delete this;
				}
				else
				{
					if(next)
					next->merge();
				}
			}
		}
};

class cslab
{
	private:
	memnode* freeHead;
	public:
	cslab()
	{}
	cslab(memnode * mem)
	{
		freeHead=new memnode(0);
		freeHead->nextFree=mem;
	}

	memnode* alloc(int size)
	{
		memnode* Matched = NULL;
		memnode* actualMatch = freeHead;
		while(actualMatch->nextFree)
		{
			if(actualMatch->nextFree->size == size)
			{
				Matched = actualMatch; 
				break;
			}
			else if(Matched == NULL 
					&& actualMatch->nextFree->size > size)
			{
				Matched = actualMatch;
			}

			actualMatch = actualMatch->nextFree;
		}
		
		if(actualMatch == freeHead)
		{
			if(!actualMatch->nextFree)
				return NULL;

		}
		
		if(Matched==NULL) return NULL;

		if(Matched->nextFree)
		{
			actualMatch = Matched->nextFree;
			if(actualMatch->size > size)
			{
				memnode* freeNode=new memnode(actualMatch->size - size);
				freeNode->startAdress=actualMatch->startAdress+size;
				freeNode->next=actualMatch->next;
				freeNode->nextFree=actualMatch->nextFree;
				freeNode->pre = actualMatch;
				actualMatch->next=freeNode;
				actualMatch->size=size;
		 		Matched->nextFree =freeNode; 
			}
			else
			{
				Matched->nextFree = Matched->nextFree->nextFree;
			}
			actualMatch->nextFree=NULL;
			actualMatch->free=false;
		}
		

		return actualMatch;
	}

	void free(memnode * node)
	{
		if(node == NULL || node->free)
		{
			throw 1;
		}

		node->free=true;
		memnode * temp = node;
		while(temp->pre && !temp->pre->free){ 
			temp=temp->pre;
	       	}
				
		if(temp->pre)
		{
			node->nextFree=temp->pre->nextFree;
			temp->pre->nextFree=node;
		}
		else
		{
			node->nextFree=freeHead->nextFree;
			freeHead->nextFree=node;
		}

		node->merge();	
	}
	void print()
	{
		memnode * temp=freeHead->nextFree;
		while(temp!=NULL)
		{
			cout<<temp->size<<"  "<<temp->startAdress<<endl;
			temp=temp->nextFree;
		}
	}

};
cslab slab;
void memnode::release()
{
	cout<<"free"<<endl;
	slab.free(this);

}
class CProcInfo
{
	public:
		int time;
		int startTime;
		int getEndTime(){return startTime+time;}
		memnode * node;
		CProcInfo(int cost, int stime, memnode * mem)
		{
			time=cost;
			startTime=stime;
			node=mem;
		}

};


class compare
{
	public:
		bool operator ()(CProcInfo& l, CProcInfo& r)
		{
			return l.getEndTime()>r.getEndTime();
		}
};

 priority_queue<CProcInfo, vector<CProcInfo>, compare> runningQueue;
 queue<CProcInfo> waitQueue;
 CProcInfo getCurrentWait()
	{
		return waitQueue.front();
	}
 void checkCompletedProc(int currentTime)
{
	while(!runningQueue.empty())
	{
		CProcInfo info= runningQueue.top();
		cout<<"end time  "<<info.getEndTime()<<endl;
		if(info.getEndTime() <= currentTime)
		{
			cout<<info.node<<" at release"<<endl;
			info.node->release();

			runningQueue.pop();
							slab.print();
			continue;
		}
		break;
	}		
}

int main()
{
	int systemtime=0;

	try
	{
		slab = cslab(new memnode(100));
		
		int time, size,stime;
		memnode * mem;
		while(cin>>stime>>time>>size)
		{
			if(time==0 && size==0)
			{
				break;
			}

			while((mem=slab.alloc(size))==NULL)
			{
				
				systemtime++;
				slab.print();

				checkCompletedProc(systemtime);		
			}

			runningQueue.push(CProcInfo(time, systemtime, mem));
		}

	}
	catch(int c)
	{
		cout<<"error"<<c;
	}
catch(...)
{
		cout<<"error unkown!\n";
}	

return 0;
}
